package main;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import stateManager.StateManager;

public class DumbTree {
	
	private ArrayList<Sprite> dumbTree; 
	ExecutorService execSvc;
	private DrawTree drawTreeA;
	private DrawTree drawTreeB;
	public StateManager stateManager;
	
	public DumbTree(){
		stateManager = StateManager.getInstance();
		execSvc = Executors.newFixedThreadPool(4);
		dumbTree = new ArrayList<Sprite>();	
	}
	
	public void setDrawTreeA(DrawTree dt){
		this.drawTreeA = dt;
	}
	
	public void setDrawTreeB(DrawTree dt){
		this.drawTreeB = dt;
	}
	
	public void insert(Sprite s){
		dumbTree.add(s);
	}
	
	public ArrayList<Sprite> think(boolean cycleA){
		
		ArrayList<Sprite> swapList = new ArrayList<Sprite>();
		ArrayList<Sprite> tmp_dumbTree = new ArrayList<Sprite>();
		int z = dumbTree.size();
		for(int i = 0; i<z; i++){			
			if(dumbTree.get(i).isAlive()){
				tmp_dumbTree.add(dumbTree.get(i));
				execSvc.execute(dumbTree.get(i));
				if(dumbTree.get(i).isCollidable()==true){
					swapList.add(dumbTree.get(i));
				}
				if(dumbTree.get(i).isVisible()){
					if(cycleA){
						drawTreeA.insert(dumbTree.get(i));
					}
					else{
						drawTreeB.insert(dumbTree.get(i));
					}
					
				}
			}
			else{
				//do nothing
			}
		}
		this.dumbTree = tmp_dumbTree;
		return swapList;
	}
	
	public  ArrayList<Sprite> getDumbTree() {
		return dumbTree;
	}
}
